import { defineStore } from "pinia";
import { getProducts,IProduct } from "../api/shop";

export const useProductsStore = defineStore('products', {
  state: () => {
    return {
      all:[] as IProduct[]
    }
  },
  getters: {
    
  },
  actions: {
    async getAllProducts() {
      const ret =await getProducts()
      this.all=ret
    },
    decrementProduct(id: number) {
      const product=this.all.find(item => item.id === id)
      if (product) {
        product.inventory-=1
      }
    }
  }
})